home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / OS2 / FILEB185.ZIP / SOURCE / DLL / FILEBAR.CPP next >
Encoding:
C/C++ Source or Header  |  1994-04-05  |  9.2 KB  |  210 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //                    FileBar - Maximize/Movement Hook DLL
  4. //
  5. //         OS/2 Application Launch Facility and WPS Shell Replacement
  6. //
  7. //                         Written By Eric A. Wolf
  8. //                 Copyright (C) 1994 - All Rights Reserved
  9. //
  10. // This source code may be used for reference ONLY!  It is provided AS-IS and no
  11. // guarantees are made as to its utility, functionality or correctness.  It is
  12. // provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
  13. // programmers in developing their own PM applications.  No modifications are
  14. // to be made to this code for re-release as a same or different product.  This
  15. // code must be distributed (in its original entirety) with the executable
  16. // portion of this product.
  17. //
  18. //          -- Please register this shareware product for $10 today --
  19. //                          See documentation for details
  20. //
  21. // DLL Project Start Date:      March  5, 1994
  22. // DLL Project Completion Date: March  6, 1994
  23. //
  24. // Written using Borland C++ for OS/2, version 1.0
  25. //
  26. // File Last Modified:          April  5, 1994
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. #define INCL_PMWIN
  30. #define INCL_WINSYS
  31. #define INCL_WIN
  32. #define INCL_PM
  33. #define INCL_WINFRAMEMGR
  34. #define DLL_NAME                 "FILEBAR"        // define the name for our DLL
  35. #define POPUPMENU                9999             // msg to send to signal popup
  36.  
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include "filebar.h"
  40.  
  41.  
  42. //------------------------------------------------------------------------------
  43. // define data we need for our DLL
  44. //------------------------------------------------------------------------------
  45. HOOKDATA hookData;                                // define data area to store
  46.                                                   // the information we need
  47.                                                   // when we hook the system
  48. LONG messageID;                                   // message to popup our menu
  49. SHORT ScreenY;                                    // height of menubar
  50. SHORT ScreenHeight;                               // useful screen remaining
  51. CHAR tmp[32];                                     // buffer to hold session titles
  52. BOOL BarAtTop;                                    // is the menubar at the top
  53. BOOL intercept;                                   // should we intercept msgs?
  54. BOOL popUpMenu;                                   // allow popup menu?
  55.  
  56.  
  57. //------------------------------------------------------------------------------
  58. // setFileBarScreen - sets internal position and size data our DLL needs to
  59. // correctly set the maximize screen data
  60. //------------------------------------------------------------------------------
  61. VOID EXPENTRY setFileBarScreen( BOOL position, LONG y, BOOL interceptMsgs, BOOL popUp, LONG msgID )
  62. {
  63.     messageID = msgID;
  64.     intercept = interceptMsgs;
  65.     popUpMenu = popUp;
  66.     BarAtTop = position;
  67.     ScreenY = y;
  68.     ScreenHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - y;
  69. }
  70.  
  71.  
  72. //------------------------------------------------------------------------------
  73. // Handle all input messages - search for WM_CHORD
  74. //------------------------------------------------------------------------------
  75. BOOL EXPENTRY FileBarInputHook(HAB habAnchor,PQMSG pqmMsg,ULONG ulFlags)
  76. {
  77.     //--------------------------------------------------------------------------
  78.     // if any window is moved, make sare FileBar is placed on top of it
  79.     //--------------------------------------------------------------------------
  80.     if ((pqmMsg->msg == messageID) && (popUpMenu)) {
  81.         WinPostMsg( hookData.hwndApp, WM_COMMAND, MPFROMLONG(POPUPMENU), MPFROMLONG(pqmMsg->hwnd) );
  82.         return TRUE;
  83.         }
  84.     return FALSE;
  85. }
  86.  
  87.  
  88. //------------------------------------------------------------------------------
  89. // FileBarHook - this is called whenever a message is sent in the system.  So,
  90. // we simply look at each message going by and if it's something dealing with
  91. // moving or maximizing, intercept and alter so that FileBar is always on top
  92. // and no maximizing covers it!
  93. //
  94. // Note:  The parameters sent to FileBarHook are defined in the SendMsg Hook
  95. //
  96. // Returns:  TRUE if the rest of the hook chain is not to be called, or FALSE
  97. //           if the rest of the hook chain should be called.
  98. //------------------------------------------------------------------------------
  99. BOOL EXPENTRY FileBarHook(HAB habAnchor,PSMHSTRUCT structurePtr,BOOL interTask)
  100. {
  101.     if (!intercept)
  102.         return FALSE;
  103.  
  104.     switch(structurePtr->msg) {
  105.         //----------------------------------------------------------------------
  106.         // if any window is moved, make sare FileBar is placed on top of it
  107.         //----------------------------------------------------------------------
  108.         case WM_MOVE: {
  109.             WinSetWindowPos( hookData.hwndApp, HWND_TOP,0,0,0,0,SWP_ZORDER);
  110.             return TRUE;
  111.             }
  112.         //----------------------------------------------------------------------
  113.         // if a window is being maximized, make it fit below or on top of the
  114.         // FileBar application window
  115.         //----------------------------------------------------------------------
  116.         case WM_WINDOWPOSCHANGED: {
  117.           // the way BocaSoft's WipeOut screen saver is designed, when it is
  118.           // running, FileBar is still visible.  So, when that screen saver is
  119.           // requesting a maximized screen, give it access to the full screen
  120.           WinQuerySessionTitle( habAnchor, 0, tmp, sizeof(tmp) );
  121.           if (strcmp( tmp, "BocaSoft WipeOut") == 0)
  122.               return FALSE;
  123.  
  124.           if (LONGFROMMP(structurePtr->mp2) & AWP_MAXIMIZED) {
  125.             PSWP pSwp = (PSWP)LONGFROMMP(structurePtr->mp1);
  126.             if ((pSwp->x>60000) && (pSwp->y>60000)) {
  127.                 SHORT xBorder = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER );
  128.                 SHORT yBorder = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER );
  129.                 if ( !BarAtTop ) {
  130.                     pSwp->x = 0 - xBorder;
  131.                     pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  132.                     pSwp->y = ScreenY - yBorder - 1;
  133.                     pSwp->cy = ScreenHeight + 2*yBorder + 1;
  134.                     WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  135.                     return TRUE;
  136.                     }
  137.                 else {
  138.                     pSwp->x = 0 - xBorder;
  139.                     pSwp->cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) + 2*xBorder;
  140.                     pSwp->y = 0 - yBorder;
  141.                     pSwp->cy = ScreenHeight + 2*yBorder;
  142.                     WinSetWindowPos( structurePtr->hwnd, 0, pSwp->x, pSwp->y, pSwp->cx, pSwp->cy, SWP_MOVE|SWP_SIZE);
  143.                     return TRUE;
  144.                     }
  145.                 }
  146.  
  147.             }
  148.           }
  149.         //----------------------------------------------------------------------
  150.         // if it is nothing we care about, pass it onto the system
  151.         //----------------------------------------------------------------------
  152.         default:
  153.             break;
  154.         }
  155.     return FALSE;
  156. }
  157.  
  158.  
  159. //------------------------------------------------------------------------------
  160. // FileBarInit - initialize FileBar DLL.  This will load in the DLL, store the
  161. // handle to the module and set the system hook so that we intercept messages
  162. //
  163. // Returns:  TRUE if successful, FALSE otherwise
  164. //------------------------------------------------------------------------------
  165. BOOL EXPENTRY FileBarInit( HWND hwnd )
  166. {
  167.    hookData.hwndApp = hwnd;
  168.  
  169.    if (DosQueryModuleHandle(DLL_NAME,&hookData.hmModule))
  170.       return FALSE;
  171.  
  172.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  173.    WinSetHook(WinQueryAnchorBlock(hookData.hwndApp),
  174.               NULLHANDLE,
  175.               HK_SENDMSG,
  176.               (PFN)FileBarHook,
  177.               hookData.hmModule);
  178.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  179.    WinSetHook(WinQueryAnchorBlock(hookData.hwndApp),
  180.               NULLHANDLE,
  181.               HK_INPUT,
  182.               (PFN)FileBarInputHook,
  183.               hookData.hmModule);
  184.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  185.    return TRUE;
  186. }
  187.  
  188.  
  189. //-------------------------------------------------------------------------
  190. // FileBarQuit - this releases the FileBar DLL
  191. // Returns:  TRUE always
  192. //-------------------------------------------------------------------------
  193. BOOL EXPENTRY FileBarQuit( VOID )
  194. {
  195.    WinReleaseHook(WinQueryAnchorBlock(hookData.hwndApp),
  196.                   NULLHANDLE,
  197.                   HK_SENDMSG,
  198.                   (PFN)FileBarHook,
  199.                   hookData.hmModule);
  200.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  201.    WinReleaseHook(WinQueryAnchorBlock(hookData.hwndApp),
  202.                   NULLHANDLE,
  203.                   HK_INPUT,
  204.                   (PFN)FileBarInputHook,
  205.                   hookData.hmModule);
  206.    WinBroadcastMsg(HWND_DESKTOP,WM_NULL,0,0,BMSG_FRAMEONLY|BMSG_POST);
  207.    return TRUE;
  208. }
  209.  
  210.